<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %>
<%@ page import="java.io.*"%>
<%@ page import="xml.response.*"%>
<%@ page import="requestInterFace.Handle.*"%>
<%@ page import="xml.root"%>
<%@ page import="util.print.printLogCat"%>
<%@ page import="org.sql.table.*"%>
<%@ page import="xml.var"%>
<%@ page import="java.util.Vector"%>
<%@ page import="java.util.Enumeration"%>
<%@ page import="jqgrid.jqgrid"%>
<%@ page import="util.check"%>
<%@ include file="../../util/paramPrint.jsp" %>
<%@ page trimDirectiveWhitespaces="true" %> 
<%   

    /*********** jqgrid ******************/
		jqgrid jq=new jqgrid();
		jq.setRows(request.getParameter(jqgrid._rows));
		jq.setSord(request.getParameter(jqgrid._sord));
		jq.setSortname(request.getParameter(jqgrid._sortname));
		jq.setPage(request.getParameter(jqgrid._page));
		jq.setOper(request.getParameter(jqgrid._oper));
		jq.setSearch(request.getParameter(jqgrid._search));
		/*************************************/
		
		String userID=(String)session.getAttribute("User_ID");
		String userType=(String)session.getAttribute("User_Type");
		
		String Order_ID = request.getParameter("Order_ID");
		String Order_Name = orderinfo.getMain_Order_Name();//
		String Order_Status = request.getParameter("Order_Status");
		String Start_AddTime = request.getParameter("Start_AddTime");
		String End_AddTime = request.getParameter("End_AddTime");
		
		String OrderSatus=request.getParameter("OrderSatus");
		
		String User_ID = request.getParameter("User_ID");
		String UP_ID = request.getParameter("UP_ID");
		String Deliver_ID = request.getParameter("Deliver_ID");
		root root=new root();
		orderinfo1_1 user=new orderinfo1_1();
		user.setLimit((jq.getPageInt()-1)*jq.getRowsInt(), jq.getRowsInt());
		if(jq.getSortname()!=null&&!jq.getSortname().equals("")){
		user.setOrder(jq.getSortname(),jq.getSord());
		}
		//管理员的主订单可以看到 的.setResultField("Payment_Price")
			user.setResultField("Order_ID").setResultField("Order_Total_Price").setResultField("Payment_Price").setResultField("Order_AddTime").setResultField("User_ID").setResultField("Deliver_ID").setResultField("Deliver_Path_ID").setResultField("Order_Status").setResultField("Info").setResultField("Info");
		//user.setOrder("Order_AddTime", "desc");
		user.setGroup("Order_ID");
		if(userType!=null&&userType.equals("1")){
			//管理员
			if(UP_ID!=null&&(!UP_ID.equals(""))){
			user.addequwhile("UP_ID"," = ",java.net.URLDecoder.decode(UP_ID,"UTF-8"));
			}
			if(User_ID!=null&&(!User_ID.equals(""))){
			user.addequwhile("User_ID"," = ",java.net.URLDecoder.decode(User_ID,"UTF-8"));
			}
			if(Deliver_ID!=null&&(!Deliver_ID.equals(""))){
			user.addequwhile("Deliver_ID"," = ",java.net.URLDecoder.decode(Deliver_ID,"UTF-8"));
			}
		}else if(userType!=null&&userType.equals("2")){
			//业务员
			user.addequwhile("UP_ID"," = ",userID);
		}else if(userType!=null&&userType.equals("3")){
			//客户
			user.addequwhile("User_ID"," = ",userID);
		}else if(userType!=null&&userType.equals("4")){
			//送货员
			user.addequwhile("Deliver_ID"," = ",userID);
		}else{
		root.setStatus("false");
		root.setMsg("未登录");
		PrintWriter pw = response.getWriter();
		pw.println(root.getXmlString());
		pw.flush();
		return ;
		}
		if(Order_ID !=null&&(!Order_ID .equals(""))){

		   user.addequwhile("Order_ID "," like ","%"+Order_ID +"%");
		}
		
		if(Order_Name!=null&&(!Order_Name.equals(""))){
		  
		    user.addequwhile("Order_Name","like","%"+Order_Name+"%");
		}
		
		
		
		if(Start_AddTime!=null&&(!Start_AddTime.equals(""))){
		  
		    user.addequwhile("Order_AddTime",">=",Start_AddTime);
		}
		
		if(End_AddTime!=null&&(!End_AddTime.equals(""))){
		  
		    user.addequwhile("Order_AddTime","<=",End_AddTime);
		}
	
	    if(OrderSatus!=null&&(!OrderSatus.equals(""))){
		  if(OrderSatus.equals("0")){
		  //查询未下单订单
		  user.addequwhile("Order_Status","=","0");
		  }else if(OrderSatus.equals("1_2")){
		  //查询未发货订单
		  user.addequwhile("Order_Status",">=","1");
		   user.addequwhile("Order_Status","<=","2");
		  }else if(OrderSatus.equals("3")){
		  //查询已发货订单
		  user.addequwhile("Order_Status",">=","3");
		   user.addequwhile("Order_Status","<=","3");
		  }else if(OrderSatus.equals("4_5")){
		  //查询已发货订单
		  user.addequwhile("Order_Status",">=","4");
		   user.addequwhile("Order_Status","<=","5");
		  }else{
		  if(Order_Status!=null&&(!Order_Status.equals(""))){
		  
		    user.addequwhile("Order_Status","=",Order_Status);
		     }
		  }
		   
		}else{
		if(Order_Status!=null&&(!Order_Status.equals(""))){
		  
		    user.addequwhile("Order_Status","=",Order_Status);
		}
		}
	
		Vector d=user.getTableFactroy();
		root.setRecords(""+d.size());//设置当前查询到的记录数
		int pageNum=user.getCount()/jq.getRowsInt();
		if((user.getCount()%jq.getRowsInt())>0){
			pageNum++;
		}
		root.setTotal_Count(""+pageNum);//查询到的总记录数
		root.setLimit_Offset(""+jq.getPage());//当前查询页面
		for(int i=0;i<d.size();i++){
			orderinfo1_1 u=(orderinfo1_1)d.elementAt(i);
		Enumeration e=u.getTable().elements();
		response res=new response();
		res.setAttribute_Id(""+i);
	for(int j=0;j<u.getResultFieldNum();j++){
			String field=(String)u.getSql().getResultField().elementAt(j);
    		var v=(var)u.getTable().get(field);
	 		if(v.getName().equals("Order_Total_Price")){
			var name=new var();
			name.setTag_this("cell");
			name.setName("Order_Total_Price");
			orderStat orderStat=new orderStat();
			var vid=(var)u.getTable().get("Order_ID");
			name.setValue(""+orderStat.getOrderTotleSaleMoney(vid.getValue()));
			res.put(name.getName(),name);
			}else{
    		res.put(v.getName(), v);
			}
		}
		root.addResponse(res);
		}
		//printLogCat.printlnWriter(root.getXmlString());
		String rep=root.getXmlString();
%>
<%=rep%>




